/**
@file
	Libraryatabase.h
@brief

@author
	GengYong
@revision
	2005/11/05 * Created by GengYong.
*/



#ifndef SAF_HEADER_FILE_ModuleManager_H
#define SAF_HEADER_FILE_ModuleManager_H

#include "../include/KernelExport.h"

namespace SAF
{
	class ModuleManager
	{
	public:
		typedef void *(*Builder)(unsigned long version, void *);
		typedef void  (*Destroyer)(void*);
	public:
		typedef struct ModuleInfo
		{
			unsigned long	signature;
			unsigned long	version;
			unsigned long	timestamp;
			unsigned long	imagesize;
			volatile long	counter;
			const char *	classname;
			void *			imagebase;
			void *			builder;
			void *			destroyer;
			void *			holder;
			void *			reserved;
			volatile bool	deprecated;
		} ModuleInfo;
	private:
		typedef struct ModuleTree
		{	
			const char	*  name;
			ModuleInfo	*  info;
			ModuleTree	*  lleaf;
			ModuleTree	*  rleaf;
		} ModuleTree;
	public:
		static ModuleManager& Instance()
		{
			static ModuleManager instance;
			return instance;
		}
	public:
		void Unload(const char * modname); 
		bool Reload(const char * modname, const char * filename);
		ModuleInfo * GetModuleInfo(const char * modname);
	public:
		void * CreateObject(const char * name);
		void DestroyObject(const char * name, void *);
	private:
		 ModuleManager();
		~ModuleManager();
		 ModuleManager(const ModuleManager&) {;}
		 ModuleManager& operator=(const ModuleManager&) { return *this; }
	private:
		ModuleTree * m_treeRoot;
	private:
		bool CleanModule(ModuleManager::ModuleInfo *);
	};
}

#endif	//#ifndef SAF_HEADER_FILE_ModuleManager_H
